package charpter11.lynx;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import net.mindview.util.TextFile;

public class TwentyTwo {
	private static class Counter implements Comparable<Counter> {
		public Counter(String string) {
			word = string;
			counter = 1;
		}

		public String getWord() {
			return word;
		}

		@SuppressWarnings("unused")
		public void setWord(String word) {
			this.word = word;
		}

		public int getCounter() {
			return counter;
		}

		public void setCounter(int counter) {
			this.counter = counter;
		}

		private String word;
		private int counter;

		@Override
		public int compareTo(Counter o) {
			word.compareTo(o.word);
			return 0;
		}
	}

	public static void main(String[] args) {
		Set<Counter> words = new HashSet<TwentyTwo.Counter>();
		if (args.length == 1) {
			boolean find = false;
			for (String string : new TextFile(args[0], "\\W")) {
				find = false;
				Counter counter = new Counter(string);
				for (Counter counter1 : words) {
					if (counter1.getWord().equals(counter.getWord())) {
						counter1.setCounter(counter1.getCounter() + 1);
						find = true;
					}
				}
				if(!find){
					words.add(counter);
				}
			}
		} else {
			System.out.println("没东西你让我统计什么啊");
		}
		ArrayList<Counter> ans = new ArrayList<TwentyTwo.Counter>(words);
		Collections.sort(ans);
		for (Counter counter : ans) {
			System.out.println(counter.getWord() + ":" + counter.getCounter());
		}
	}
}
